#include <REGX52.H>
#include "type.h"

// 设置变量用于检测是否暂停 来判断是否假暂停、清零
unsigned char stopwatch_pause = 0;
// 设置变量来判断当前是否为假暂停
unsigned char stopwatch_fake_pause = 0;

extern time stopwatch;

// 秒表清零
void clear_stopwatch(){
	time* t = &stopwatch;
	// 秒表清零并显示
	t->h = t->min = t->s = t->ms_10 = 0;
	LCD_ShowTime();
}

// 秒表按键1功能
void stopwatch_Key1(){
	// 先赋值后反转可以确保每次暂停时 stopwatch_pause置1
	stopwatch_pause = TR2;
	TR2 = ~TR2;
}

// 秒表按键2功能
void stopwatch_Key2(){
	// 若暂停则清零
	if(stopwatch_pause){
		clear_stopwatch();
	}
	// 如果未开始（stopwatch所有位都是0）则不会触发假暂停判断
	else if((!stopwatch.h)&&(!stopwatch.min)&&(!stopwatch.s)){
	}
	else{
		// 开始/停止假暂停
		stopwatch_fake_pause = ~stopwatch_fake_pause;
		LCD_ShowTime();
	}
}